// pages/customer/customer.js
var App = getApp();
function jsonSort(jsonObj) {
    let arr = [];
    for (var key in jsonObj) {
        arr.push(key)
    }
    arr.sort();
    let str = '';
    for (var i in arr) {
        str += arr[i] + "=" + jsonObj[arr[i]] + "&"
    }
    return str.substr(0, str.length - 1)
}
Page({

    /**
     * 页面的初始数据
     */
    data: {
        customer_list: [],
        search: 0,
    },
    /**
         * 生命周期函数--监听页面显示
         */
    onShow: function () {
        this.onLoad();
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.laoding();
    },
    laoding() {
        var This = this;
        var name = This.data.search
        App._get('coach/member/get_new_member_data', {
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            // store_id: 53,
            // openid: 1,
            // phone: 15612340001,
            keyword: name
        }, function (res) {
            if (res.status == 1) {
                This.setData({
                    customer_list: res.data
                })
            } else {
                wx.showToast({
                    title: res.error.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    //详情
    vc_detail(e) {
        wx.navigateTo({
            url: '/pages/latent_maintenance/latent_maintenance?id=' + e.currentTarget.id + '&type=' + 1,
        })
    },
    //搜索
    wxSearchInput(e) {
        console.log(e.detail.value)
        var This = this;
        This.setData({
            search: e.detail.value
        })
        if (e.detail.value == '') {
            This.setData({
                search: 0
            })
        }
        This.laoding();
    },
    call_phone(e) {
        console.log(e)
        wx.makePhoneCall({
            phoneNumber: e.currentTarget.id,
        })
    },
    add_passenger(e) {
        wx.navigateTo({
            url: '/pages/add_the_maintenance/add_the_maintenance?id=' + e.currentTarget.id + '&type=1',
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})